package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.CalculEstimation;
import metier.entities.Devise;



@Stateless(name="CIMP")
public class CalculeEJBImpl implements ICalculEstimationLocal,ICalculEstimationRemote{

	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;
	
	
	@Override
	public void addCalcule(CalculEstimation c) {
		em.persist(c);
		
	}

	@Override
	public List<CalculEstimation> getAllCalcule() {
		Query req=em.createQuery("select c from CalculEstimation c");
		return req.getResultList();
	}

	@Override
	public CalculEstimation getCalcule(Integer Id) {
		CalculEstimation de=em.find(CalculEstimation.class, Id);
		if(de==null)throw new RuntimeException("Estimation introuvable");
		return de;
	}

	@Override
	public void updateCalcule(CalculEstimation d) {
		em.merge(d);
	}
 
	@Override
	public void deleteCalcule(Integer Id) {
		CalculEstimation cal=getCalcule(Id);
		em.remove(cal);
	}
	

}
